package com.aptemo.webetek.server.handlers;

import com.aptemo.webetek.client.commands.Action;
import com.aptemo.webetek.client.commands.impl.ModifyGameAction;
import com.aptemo.webetek.client.exceptions.BackendException;
import com.aptemo.webetek.client.exceptions.WebetekLoginException;
import com.aptemo.webetek.client.exceptions.BackendException.EErrorCodes;
import com.aptemo.webetek.server.datastore.DataStoreAPI;
import com.aptemo.webetek.shared.EventBean;

public class ModifyEventHandler
		extends ActionHandler<ModifyGameAction, EventBean>
{

	public ModifyEventHandler(DataStoreAPI dataService)
	{
		super(dataService);
	}

	public Class<? extends Action<?>> getActionType()
	{
		return ModifyGameAction.class;
	}

	@Override
	public EventBean invoke(ModifyGameAction action) throws BackendException, WebetekLoginException
	{
		utils.checkLogin();
		
		if (!utils.isTeamEditor(action.getTeamId()))
		{
			throw new BackendException(EErrorCodes.NOT_TEAM_EDITOR);
		}
		// return mparent.modifyGame(action.getBet());
		return dataService.modifyEvent(action.getBet());
	}
}
